import pandas as pd
import tushare as ts
from datetime import datetime, timedelta
import common.base_profile as pf


# 设置你的 Tushare token
ts.set_token(pf.token)

# 初始化接口
pro = ts.pro_api()


def get_tencent_hk_data():
    """获取腾讯控股最近两个月的港股数据"""
    pro = ts.pro_api()

    end_date = datetime.now().strftime('%Y%m%d')
    start_date = (datetime.now() - timedelta(days=60)).strftime('%Y%m%d')

    # df = pro.hk_daily(ts_code='00700.HK', start_date=start_date, end_date=end_date)
    df = pro.hk_daily(ts_code='00700.HK')
    # 写入 CSV 文件
    csv = "../data/tx_daily.csv"
    df.to_csv(csv, index=False, encoding='utf-8-sig')
    print(f"数据已成功写入 {csv}")

if __name__ == '__main__':
    get_tencent_hk_data()